@watalabs/lasee-mditor 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -138
- package/dist/index.js +2 -2
- package/dist/lasee-mditor.umd.js +1 -1
- package/dist/{editor-B1BHeyw9.js → mditor-rUMGNL2Q.js} +1 -1
- package/dist/react.js +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/react.d.ts +7 -7
- package/dist/types/ui/{editor.d.ts → mditor.d.ts} +10 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,231 +1,253 @@
|
|
|
1
1
|
# @watalabs/lasee-mditor
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[MDitor LaSee](https://lasee.watalabs.com)
|
|
3
|
+
A WYSIWYG Markdown document editor: **edit what you see, keep Markdown as the source of truth.**
|
|
4
|
+
It is the editor from [MDitor LaSee](https://lasee.watalabs.com/en/), packaged as a library. It runs entirely in the browser — no server needed.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
- Framework-free core, an optional **React** wrapper, and a `<script>` bundle (UMD)
|
|
7
|
+
- English and Korean UI (every string can be replaced)
|
|
8
|
+
- The output Markdown is always one canonical form: the same document gives the same Markdown, byte for byte the same as the MDitor server that renders the PDF
|
|
7
9
|
|
|
8
|
-
-
|
|
9
|
-
- **표** — 행 · 열 넣기/지우기, 칸 합치기 · 나누기, 칸 음영, 열 정렬 (표 안에 커서가 있으면 표 도구가 나온다)
|
|
10
|
-
- **입력 규칙** — `- ` 글머리, `1. ` 번호, `[ ] ` 할 일, `## ` `### ` 제목, `> ` 비고, ```` ``` ```` 코드 블록, `---` 가로줄, `**굵게**` `==형광펜==` `` `코드` ``
|
|
11
|
-
- **MD 붙여넣기** — Markdown 글을 붙이면 문서로 읽어 넣는다(Shift 붙여넣기는 글 그대로). 워드 · 구글 문서에서 붙인 표 · 목록 · 링크도 받는다.
|
|
12
|
-
- **글자 수** · **읽기 전용** · **ko / en 화면 글**(바꿔 쓸 수 있다)
|
|
13
|
-
- 출력 MD 는 언제나 하나의 표준 꼴이다(같은 문서는 같은 MD). MDitor 서버(PDF)와 바이트 단위로 같은 규칙을 쓴다.
|
|
10
|
+
**Source:** [github.com/madorik/mditor-lasee](https://github.com/madorik/mditor-lasee/tree/main/web/packages/lasee-mditor) · **License:** MIT
|
|
14
11
|
|
|
15
|
-
##
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Toolbar** — undo/redo · block type (body, heading, subheading, list, note, code block, document title) · bold · italic · underline · strikethrough · text color (palette or color code) · shade · highlight · link · inline code · superscript/subscript · clear formatting · bulleted, numbered and to-do lists · indent/outdent · paragraph alignment · tables (pick a size) · images (URL, file, paste, drag and drop) · code block · horizontal line · page break · special characters · find and replace · Markdown source mode · preview on/off · full screen
|
|
15
|
+
- **Tables** — insert/delete rows and columns, merge and split cells, cell shading, column alignment (a table toolbar appears when the cursor is in a table)
|
|
16
|
+
- **Input rules** — `- ` bullets, `1. ` numbers, `[ ] ` to-dos, `## ` `### ` headings, `> ` note, ```` ``` ```` code block, `---` line, `**bold**`, `==highlight==`, `` `code` ``
|
|
17
|
+
- **Smart paste** — pasted Markdown is parsed into the document (Shift-paste keeps plain text). Tables, lists and links pasted from Word or Google Docs are kept.
|
|
18
|
+
- **Paste limits** — cap the characters per paste and the document length, so one huge paste can't freeze the page or your server
|
|
19
|
+
- **Status bar** with character and word counts · **read-only mode** · **automatic page-break marks** fed by your own page layout
|
|
20
|
+
|
|
21
|
+
## Install
|
|
16
22
|
|
|
17
23
|
```bash
|
|
18
24
|
npm install @watalabs/lasee-mditor
|
|
19
25
|
```
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
## 쓰기
|
|
27
|
+
## Usage
|
|
24
28
|
|
|
25
|
-
###
|
|
29
|
+
### Plain JavaScript / TypeScript (ESM)
|
|
26
30
|
|
|
27
31
|
```ts
|
|
28
|
-
import {
|
|
32
|
+
import { createMDitor } from "@watalabs/lasee-mditor";
|
|
29
33
|
import "@watalabs/lasee-mditor/style.css";
|
|
30
34
|
|
|
31
|
-
const
|
|
32
|
-
element: document.querySelector("#
|
|
33
|
-
markdown: "#
|
|
34
|
-
locale: "
|
|
35
|
-
preview: true, //
|
|
35
|
+
const mditor = createMDitor({
|
|
36
|
+
element: document.querySelector("#mditor")!,
|
|
37
|
+
markdown: "# Title\n\nBody text\n",
|
|
38
|
+
locale: "en", // UI language: "en" | "ko" (default "ko")
|
|
39
|
+
preview: true, // open the preview pane (users toggle it from the toolbar)
|
|
40
|
+
maxPaste: 5000, // reject pastes longer than 5,000 characters
|
|
36
41
|
onChange: (md) => console.log(md),
|
|
37
42
|
});
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
mditor.getMarkdown();
|
|
45
|
+
mditor.setMarkdown("## New text\n");
|
|
41
46
|
```
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
Give the editor a height — it fills its container (`.mde` is a flex column with a minimum height of 320px):
|
|
49
|
+
|
|
50
|
+
```css
|
|
51
|
+
#mditor .mde { height: 600px; }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### One `<script>` tag (UMD)
|
|
44
55
|
|
|
45
56
|
```html
|
|
46
57
|
<link rel="stylesheet" href="https://unpkg.com/@watalabs/lasee-mditor/dist/style.css" />
|
|
47
58
|
<script src="https://unpkg.com/@watalabs/lasee-mditor/dist/lasee-mditor.umd.js"></script>
|
|
48
|
-
|
|
59
|
+
|
|
60
|
+
<div id="mditor" style="height: 600px"></div>
|
|
49
61
|
<script>
|
|
50
|
-
const
|
|
62
|
+
const mditor = LaSeeMDitor.createMDitor({
|
|
63
|
+
element: document.getElementById("mditor"),
|
|
64
|
+
markdown: "# Hello\n",
|
|
65
|
+
locale: "en",
|
|
66
|
+
});
|
|
51
67
|
</script>
|
|
52
68
|
```
|
|
53
69
|
|
|
70
|
+
The bundle defines the global `LaSeeMDitor` with everything the ESM entry exports. Pin a version in production (`…/lasee-mditor@0.2.0/dist/…`).
|
|
71
|
+
|
|
54
72
|
### React
|
|
55
73
|
|
|
56
74
|
```tsx
|
|
57
|
-
import {
|
|
75
|
+
import { useState } from "react";
|
|
76
|
+
import { MDitorView } from "@watalabs/lasee-mditor/react";
|
|
58
77
|
import "@watalabs/lasee-mditor/style.css";
|
|
59
78
|
|
|
60
79
|
function Page() {
|
|
61
|
-
const [md, setMd] = useState("#
|
|
62
|
-
return <
|
|
80
|
+
const [md, setMd] = useState("# Title\n");
|
|
81
|
+
return <MDitorView value={md} onChange={setMd} locale="en" preview style={{ height: 600 }} />;
|
|
63
82
|
}
|
|
64
83
|
```
|
|
65
84
|
|
|
66
|
-
`ref`
|
|
85
|
+
`react` and `react-dom` are optional peer dependencies — install them yourself. A `ref` gives you the `MDitor` instance. Use `toolbarStart` / `toolbarEnd` to put your own buttons at either end of the toolbar. The editor is created once; later prop changes follow `value`, `editable`, `dialect` and `preview` (change the `key` to recreate it with other options).
|
|
67
86
|
|
|
68
|
-
###
|
|
87
|
+
### No UI — parse, write, render HTML
|
|
69
88
|
|
|
70
89
|
```ts
|
|
71
|
-
import { parseMarkdown, docToMarkdown, renderHtml } from "@watalabs/lasee-mditor/core"; // TipTap
|
|
90
|
+
import { parseMarkdown, docToMarkdown, renderHtml } from "@watalabs/lasee-mditor/core"; // no TipTap, no DOM
|
|
72
91
|
|
|
73
|
-
const doc = parseMarkdown(md); //
|
|
74
|
-
docToMarkdown(doc); //
|
|
75
|
-
renderHtml(md); //
|
|
92
|
+
const doc = parseMarkdown(md); // Markdown → document (JSON); throws MdError(line, code) on invalid input
|
|
93
|
+
docToMarkdown(doc); // document → canonical Markdown
|
|
94
|
+
renderHtml(md); // Markdown → HTML (only safe link URLs)
|
|
76
95
|
```
|
|
77
96
|
|
|
78
|
-
|
|
97
|
+
Works on a server or in a worker.
|
|
79
98
|
|
|
80
|
-
|
|
99
|
+
## Options
|
|
100
|
+
|
|
101
|
+
| Name | Default | Description |
|
|
81
102
|
|---|---|---|
|
|
82
|
-
| `element` | (
|
|
83
|
-
| `markdown` / `doc` | `""` |
|
|
84
|
-
| `locale` | `"ko"` |
|
|
85
|
-
| `messages` | |
|
|
86
|
-
| `dialect` |
|
|
87
|
-
| `toolbar` | `DEFAULT_TOOLBAR` |
|
|
88
|
-
| `preview` | `false` |
|
|
89
|
-
| `pageMarks` | `false` |
|
|
90
|
-
| `mode` | `"wysiwyg"` |
|
|
91
|
-
| `statusbar` | `true` |
|
|
92
|
-
| `editable` | `true` |
|
|
93
|
-
| `placeholder` | |
|
|
94
|
-
| `contentClass` | `"mde-doc"` |
|
|
95
|
-
| `image.upload` | data:
|
|
96
|
-
| `image.resolve` |
|
|
97
|
-
| `image.onFiles` / `image.pick` | |
|
|
98
|
-
| `onChange` | | `(markdown,
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
| `element` | (required) | Element to mount the editor in |
|
|
104
|
+
| `markdown` / `doc` | `""` | Initial content (Markdown, or a document JSON) |
|
|
105
|
+
| `locale` | `"ko"` | UI language, `"en"` or `"ko"` |
|
|
106
|
+
| `messages` | | Override UI strings (`Partial<Messages>`) |
|
|
107
|
+
| `dialect` | auto | Formatting tag names — `{red}` or `{빨강}`. Defaults to the first tag found in the Markdown, otherwise `locale` |
|
|
108
|
+
| `toolbar` | `DEFAULT_TOOLBAR` | Toolbar items; `false` for no toolbar |
|
|
109
|
+
| `preview` | `false` | Open the preview pane |
|
|
110
|
+
| `pageMarks` | `false` | Show page-break marks from the start (you supply them with `setPageMarks`) |
|
|
111
|
+
| `mode` | `"wysiwyg"` | Initial mode; `"source"` for the Markdown source |
|
|
112
|
+
| `statusbar` | `true` | Character and word counts |
|
|
113
|
+
| `editable` | `true` | Allow editing |
|
|
114
|
+
| `placeholder` | | Hint shown in an empty document |
|
|
115
|
+
| `contentClass` | `"mde-doc"` | Class of the document area (to use your own document styles) |
|
|
116
|
+
| `image.upload` | data: URL | `(file) => Promise<url>` — upload a file and return the URL to write in the document |
|
|
117
|
+
| `image.resolve` | as written | Map an image name in the document to the URL to display |
|
|
118
|
+
| `image.onFiles` / `image.pick` | | Handle image files / the image button yourself |
|
|
119
|
+
| `onChange` | | `(markdown, mditor) => void` |
|
|
120
|
+
| `maxPaste` | none | Characters allowed in one paste; longer pastes are rejected |
|
|
121
|
+
| `maxLength` | none | Document (Markdown) length limit; pastes that would exceed it are rejected. Typing is never blocked |
|
|
122
|
+
| `onTooLong` | a notice above the editor | `({ kind: "paste" \| "document", length, max }) => void` — called when a paste is rejected |
|
|
123
|
+
| `extensions` | | Extra TipTap extensions |
|
|
124
|
+
|
|
125
|
+
### Toolbar items
|
|
104
126
|
|
|
105
127
|
`undo` `redo` `blockKind` `bold` `italic` `underline` `strike` `color` `highlight` `link` `code` `superscript` `subscript` `removeFormat`
|
|
106
128
|
`bulletList` `orderedList` `taskList` `outdent` `indent` `align` `table` `image` `codeBlock` `horizontalRule` `pageBreak` `specialChars`
|
|
107
|
-
`find` `source` `preview` `fullscreen` `pageMarks`(
|
|
129
|
+
`find` `source` `preview` `fullscreen` `pageMarks` (not in the default toolbar), the separator `"|"`, and custom items `{ name, render: (mditor) => HTMLElement }`.
|
|
108
130
|
|
|
109
131
|
```ts
|
|
110
|
-
|
|
132
|
+
createMDitor({
|
|
133
|
+
element,
|
|
134
|
+
toolbar: ["bold", "italic", "|", "link", "|", "preview", { name: "save", render: () => mySaveButton }],
|
|
135
|
+
});
|
|
111
136
|
```
|
|
112
137
|
|
|
113
|
-
##
|
|
138
|
+
## The `MDitor` instance
|
|
114
139
|
|
|
115
|
-
| | |
|
|
140
|
+
| Method | |
|
|
116
141
|
|---|---|
|
|
117
|
-
| `getMarkdown()` · `setMarkdown(md)` |
|
|
118
|
-
| `getDoc()` · `setDoc(doc)` · `getHTML()` |
|
|
119
|
-
| `setMode("wysiwyg" \| "source")` |
|
|
120
|
-
| `setPreview(on)` · `isPreview()` |
|
|
121
|
-
| `setPageMarks(marks)` · `setPageMarksVisible(on)` · `isPageMarksVisible()` |
|
|
142
|
+
| `getMarkdown()` · `setMarkdown(md)` | Read or replace the Markdown (`setMarkdown` throws `MdError` on invalid Markdown) |
|
|
143
|
+
| `getDoc()` · `setDoc(doc)` · `getHTML()` | Document JSON · the preview HTML |
|
|
144
|
+
| `setMode("wysiwyg" \| "source")` · `getMode()` | Switch between the document and the Markdown source. Returns `false` and shows the error line if the source can't be parsed |
|
|
145
|
+
| `setPreview(on)` · `isPreview()` | Show or hide the preview |
|
|
146
|
+
| `setPageMarks(marks)` · `setPageMarksVisible(on)` · `isPageMarksVisible()` | Automatic page-break marks |
|
|
122
147
|
| `setFullscreen(on)` · `setEditable(on)` · `setDialect(d)` | |
|
|
123
|
-
| `insertImage(src, caption?)` · `replaceImage(from, to)` · `refreshImages()` |
|
|
124
|
-
| `on("change" \| "mode" \| "preview" \| "fullscreen" \| "pagemarks", fn)` |
|
|
125
|
-
| `slot("start" \| "end")` |
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
148
|
+
| `insertImage(src, caption?)` · `replaceImage(from, to)` · `refreshImages()` | Images |
|
|
149
|
+
| `on("change" \| "mode" \| "preview" \| "fullscreen" \| "pagemarks", fn)` | Events; returns an unsubscribe function |
|
|
150
|
+
| `slot("start" \| "end")` | Empty slots at either end of the toolbar for your own buttons |
|
|
151
|
+
| `focus()` · `destroy()` | |
|
|
152
|
+
| `tiptap` | The underlying TipTap `Editor` |
|
|
128
153
|
|
|
129
|
-
|
|
154
|
+
**Shortcuts** (Ctrl instead of ⌘ on Windows/Linux): bold ⌘B · italic ⌘I · underline ⌘U · code ⌘E · link ⌘K · highlight ⌘⇧H · superscript/subscript ⌘. / ⌘, · numbered/bulleted/to-do list ⌘⇧7 / 8 / 9 · body/heading/subheading ⌘⌥0 / 2 / 3 · page break ⌘Enter · find ⌘F · indent Tab / ⇧Tab.
|
|
130
155
|
|
|
131
|
-
###
|
|
156
|
+
### Automatic page-break marks
|
|
132
157
|
|
|
133
|
-
|
|
134
|
-
자리는 문서(JSON)의 순번으로 적는다 — 편집기가 같은 규칙으로 블록을 묶으므로 순번이 맞는다.
|
|
158
|
+
The editor never guesses where pages end — you compute that and pass it in. (The MDitor server's `POST /api/md/preview-pages` returns the layout of the actual PDF.) Positions use indexes into the document JSON; the editor groups blocks by the same rules, so the indexes match.
|
|
135
159
|
|
|
136
160
|
```ts
|
|
137
|
-
|
|
161
|
+
mditor.setPageMarks({
|
|
138
162
|
total: 4,
|
|
139
|
-
sections: { 2: 3 }, //
|
|
163
|
+
sections: { 2: 3 }, // the third section (## …) starts on page 3
|
|
140
164
|
blocks: {
|
|
141
|
-
0: { items: { 12: 2 } }, //
|
|
142
|
-
5: { rows: { 30: 4 } }, //
|
|
143
|
-
7: { before: 4 }, //
|
|
165
|
+
0: { items: { 12: 2 } }, // in the first block (a list), page 2 starts at the 13th item
|
|
166
|
+
5: { rows: { 30: 4 } }, // in the sixth block (a table), page 4 starts at the 31st body row
|
|
167
|
+
7: { before: 4 }, // a new page starts before the eighth block
|
|
144
168
|
},
|
|
145
169
|
});
|
|
146
|
-
|
|
170
|
+
mditor.setPageMarksVisible(true); // or the "pageMarks" toolbar item
|
|
147
171
|
```
|
|
148
172
|
|
|
149
|
-
|
|
173
|
+
Until new marks arrive, existing marks follow the text as it's edited. Marks are never written to the Markdown. While they're on, the status bar shows the page count.
|
|
150
174
|
|
|
151
|
-
##
|
|
175
|
+
## Syntax
|
|
152
176
|
|
|
153
|
-
|
|
177
|
+
A subset of CommonMark/GFM plus MDitor's report syntax. Any Markdown viewer can still read it.
|
|
154
178
|
|
|
155
179
|
```markdown
|
|
156
|
-
#
|
|
157
|
-
##
|
|
158
|
-
###
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
{
|
|
162
|
-
{
|
|
163
|
-
|
|
164
|
-
-
|
|
165
|
-
-
|
|
166
|
-
1.
|
|
167
|
-
- [ ]
|
|
168
|
-
- [x]
|
|
169
|
-
>
|
|
170
|
-
|
|
171
|
-
|
|
|
172
|
-
| ^ |
|
|
180
|
+
# Document title
|
|
181
|
+
## Heading (section)
|
|
182
|
+
### Subheading (block title)
|
|
183
|
+
|
|
184
|
+
**bold** ~~strike~~ ==highlight== `code` [link](https://example.com) H<sub>2</sub>O x<sup>2</sup>
|
|
185
|
+
{italic}italic{/italic} {underline}underline{/underline} {shade}shade{/shade} {red}red{/red} {#2e8b57}any color{/#2e8b57}
|
|
186
|
+
{center}A centered paragraph{/center} ← also {right} {justify}
|
|
187
|
+
|
|
188
|
+
- Bullet
|
|
189
|
+
- Nested (up to 3 levels)
|
|
190
|
+
1. Numbered
|
|
191
|
+
- [ ] To-do
|
|
192
|
+
- [x] Done
|
|
193
|
+
> Note (small text under the block)
|
|
194
|
+
|
|
195
|
+
| Head | Merged head | < |
|
|
196
|
+
| ^ | Left | Right |
|
|
173
197
|
|:---|:---|---:|
|
|
174
|
-
|
|
|
175
|
-
|
|
176
|
-

|
|
198
|
+
| Cell | {shade}Shaded cell{/shade} | 1 |
|
|
177
199
|
|
|
178
|
-
|
|
179
|
-
코드 블록
|
|
180
|
-
```
|
|
200
|
+

|
|
181
201
|
|
|
182
|
-
--- ←
|
|
183
|
-
<!-- pagebreak --> ←
|
|
202
|
+
--- ← horizontal line
|
|
203
|
+
<!-- pagebreak --> ← page break (PDF)
|
|
184
204
|
```
|
|
185
205
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
-
|
|
206
|
+
Code blocks use ```` ``` ```` fences with an optional language.
|
|
207
|
+
|
|
208
|
+
- Tags: `{red}` `{blue}` `{gray}` or any `{#rrggbb}`, `{italic}` `{underline}` `{shade}`, `{center}` `{right}` `{justify}`. Each also has a Korean name (`{빨강}` = `{red}`, `{가운데}` = `{center}`); a document uses one set.
|
|
209
|
+
- In tables, `<` merges a cell into the one on its left and `^` into the one above.
|
|
210
|
+
- Escape a symbol with `\` to write it literally: `\*\*`, `\[`, `` \` ``, `1\.`.
|
|
211
|
+
- Not supported: `*italic*` (use `{italic}`), headings below `###`, footnotes, math, video.
|
|
212
|
+
|
|
213
|
+
Full guide: [lasee.watalabs.com/en/syntax](https://lasee.watalabs.com/en/syntax).
|
|
189
214
|
|
|
190
|
-
##
|
|
215
|
+
## Styling
|
|
191
216
|
|
|
192
|
-
|
|
217
|
+
Every class starts with `.mde`. Colors and fonts are CSS variables:
|
|
193
218
|
|
|
194
219
|
```css
|
|
195
|
-
.my-
|
|
220
|
+
.my-app .mde {
|
|
196
221
|
--mde-accent: #6d28d9;
|
|
197
|
-
--mde-font: "
|
|
222
|
+
--mde-font: "Inter", sans-serif;
|
|
198
223
|
--mde-doc-width: 720px;
|
|
199
224
|
--mde-min-height: 480px;
|
|
200
225
|
}
|
|
201
226
|
```
|
|
202
227
|
|
|
203
|
-
|
|
228
|
+
To style the document area yourself, pass `contentClass: "my-doc"` and style `h1 h2 h3 p .md-list li[data-num] .md-check table pre code hr .md-pagebreak .md-note mark.md-mark` under that class.
|
|
204
229
|
|
|
205
|
-
##
|
|
230
|
+
## Development
|
|
231
|
+
|
|
232
|
+
The package lives in the [mditor-lasee](https://github.com/madorik/mditor-lasee) repository under `web/packages/lasee-mditor`.
|
|
206
233
|
|
|
207
234
|
```bash
|
|
208
|
-
cd web/packages/
|
|
209
|
-
npm run build # dist/: index.js · core.js · react.js(ESM)
|
|
210
|
-
npm run dev # demo/ —
|
|
211
|
-
cd ../.. && npx vitest run packages #
|
|
235
|
+
cd web/packages/lasee-mditor
|
|
236
|
+
npm run build # dist/: index.js · core.js · react.js (ESM), lasee-mditor.umd.js, style.css, types/
|
|
237
|
+
npm run dev # demo/ — try it without a server
|
|
238
|
+
cd ../.. && npx vitest run packages # tests, including the fixture shared with the server
|
|
212
239
|
```
|
|
213
240
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
241
|
+
| Path | Contents |
|
|
242
|
+
|---|---|
|
|
243
|
+
| `src/core/` | Inline formatting, Markdown parse/write, HTML — the **same rules** as the server's `src/mditor/inline.py` and `md.py` (change both) |
|
|
244
|
+
| `src/pm/` | TipTap schema, document ↔ editor conversion, commands, plugins (list numbers, find, page marks) |
|
|
245
|
+
| `src/ui/` | Toolbar, popovers, find and replace, source mode, preview, UI strings |
|
|
246
|
+
| `src/react.tsx` | React wrapper |
|
|
247
|
+
| `src/fixture.json` | Shared fixture generated by the server tests (`tests/test_fixture.py`) |
|
|
220
248
|
|
|
221
|
-
|
|
249
|
+
Publishing: `npm publish` from this folder (it builds first via `prepublishOnly`; check the contents with `npm pack --dry-run`). The `watalabs` npm account uses two-factor auth, so add `--otp=<code>`.
|
|
222
250
|
|
|
223
|
-
##
|
|
251
|
+
## License
|
|
224
252
|
|
|
225
|
-
|
|
226
|
-
|---|---|
|
|
227
|
-
| `src/core/` | 글 서식 · MD 읽기 · 쓰기 · HTML — 서버 `src/mditor/inline.py` `md.py` 와 **같은 규칙**(고치면 둘 다) |
|
|
228
|
-
| `src/pm/` | TipTap 스키마 · 변환(문서 ↔ 편집기) · 명령 · 플러그인(번호 · 찾기) |
|
|
229
|
-
| `src/ui/` | 도구 막대 · 팝업 · 찾아 바꾸기 · 원문 · 미리보기 · 화면 글 |
|
|
230
|
-
| `src/react.tsx` | React 감싸개 |
|
|
231
|
-
| `src/fixture.json` | 공유 기준 파일 — 서버 테스트(`tests/test_fixture.py`)가 만든다 |
|
|
253
|
+
[MIT](LICENSE) © WataLabs
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { A as e, B as t, C as n, D as r, E as i, F as a, I as o, L as s, M as c, N as l, O as u, P as d, R as f, S as p, T as m, V as h, _ as g, a as _, b as v, c as y, d as b, f as x, g as S, h as C, i as w, j as T, k as E, l as D, n as O, o as k, r as A, s as j, t as M, u as N, v as P, w as F, x as I, y as L, z as R } from "./html-BGPHBFj_.js";
|
|
2
2
|
import "./core.js";
|
|
3
|
-
import { C as z, S as B, _ as V, a as H, b as U, c as W, d as G, f as K, g as q, h as J, i as Y, l as X, m as Z, n as Q, o as $, p as ee, r as te, s as ne, t as re, u as ie, v as ae, x as oe, y as se } from "./
|
|
4
|
-
export { re as DEFAULT_TOOLBAR, W as FindReplace, p as INLINE_COLORS, X as ListNumbers, n as MARK, b as MAX_COLS, x as MAX_LEVEL, P as MdError, ie as PageMarksExtension, F as SHADE, m as SPACES, i as blockAlign, M as blockHtml, k as blockMd, r as canon, L as canonical, u as cellShade, j as codeFence, E as colorCss, te as colorName, z as commands, Q as
|
|
3
|
+
import { C as z, S as B, _ as V, a as H, b as U, c as W, d as G, f as K, g as q, h as J, i as Y, l as X, m as Z, n as Q, o as $, p as ee, r as te, s as ne, t as re, u as ie, v as ae, x as oe, y as se } from "./mditor-rUMGNL2Q.js";
|
|
4
|
+
export { re as DEFAULT_TOOLBAR, W as FindReplace, p as INLINE_COLORS, X as ListNumbers, n as MARK, b as MAX_COLS, x as MAX_LEVEL, P as MdError, ie as PageMarksExtension, F as SHADE, m as SPACES, i as blockAlign, M as blockHtml, k as blockMd, r as canon, L as canonical, u as cellShade, j as codeFence, E as colorCss, te as colorName, z as commands, Q as createMDitor, e as dialectOf, y as docToMarkdown, O as escapeHtml, G as findKey, J as fromPM, A as inlineHtml, q as inlineToMd, V as inlineToPM, T as isColor, D as itemLines, w as itemNumbers, c as linkHref, K as listNumbers, v as marker, H as messagesEn, ne as messagesFor, $ as messagesKo, l as normalize, d as oneSpace, ee as pageMarkPlaces, Z as pageMarksKey, C as parseBlocks, S as parseMarkdown, a as plainInline, ae as pmToDoc, o as pyStrip, _ as renderHtml, Y as richExtensions, s as safeHref, N as sectionMd, f as segments, I as spans, g as splitCells, se as tableData, U as tableMd, R as tag, t as title, oe as titleToMd, B as toPM, h as write };
|
package/dist/lasee-mditor.umd.js
CHANGED
|
@@ -174,4 +174,4 @@ img.ProseMirror-separator {
|
|
|
174
174
|
`,`
|
|
175
175
|
`),r=n.replace(/\n/g,``).length,i=(n.match(/\S+/g)??[]).length,a=u&&d&&s===`wysiwyg`?` · ${ZC(t.pagesTotal,{n:d.total})}`:``;ie.textContent=`${ZC(t.chars,{n:r.toLocaleString()})} · ${ZC(t.words,{n:i.toLocaleString()})}${a}`},ye=e=>{let n=ZC(t[e.code]??e.message,e.params);return e.line?ZC(t.sourceError,{line:e.line,message:n}):ZC(t.sourceErrorNoLine,{message:n})},be=e=>{b.hidden=!e,b.textContent=e?ye(e):``},xe=()=>{let e=T,t=e.state,n=t.selection.$from.parent;return{source:s===`source`,editable:e.isEditable,kind:ev(t),marks:n.type.allowsMarkType(t.schema.marks.bold),bold:e.isActive(`bold`),italic:e.isActive(`italic`),underline:e.isActive(`underline`),strike:e.isActive(`strike`),code:e.isActive(`code`),sup:e.isActive(`superscript`),sub:e.isActive(`subscript`),highlight:e.isActive(`mdHighlight`),shade:e.isActive(`mdShade`),color:e.isActive(`mdColor`)?e.getAttributes(`mdColor`).name??null:null,link:e.isActive(`link`)?e.getAttributes(`link`).href??``:null,list:ov(t),align:lv(t),inTable:e.isActive(`table`),inCode:n.type.name===`codeBlock`,canUndo:e.can().undo(),canRedo:e.can().redo()}},Se=[],Ce=e=>e.editable&&!e.source,Te=e=>Ce(e)&&e.marks;function O(e,n,r,i,a={}){let o=a.shortcut?ZC(t.shortcut,{label:n,key:Hw(a.shortcut)}):n,s=Q(`button`,{className:`mde-btn${a.word?` word`:``}`,html:r,title:o,attrs:{type:`button`,"data-name":e,"aria-label":n},on:{click:i}});return Se.push({update:e=>{s.disabled=!(a.enabled??Ce)(e),a.pressed&&s.setAttribute(`aria-pressed`,String(a.pressed(e)))}}),s}function Ee(e,n,r,i,a={}){let o=Q(`button`,{className:`mde-btn`,title:a.shortcut?ZC(t.shortcut,{label:n,key:Hw(a.shortcut)}):n,attrs:{type:`button`,"data-name":e,"aria-label":n}}),s=Tw(f,o,i),c=``;return Se.push({update:e=>{let t=r(e);t!==c&&(o.innerHTML=c=t),o.disabled=!(a.enabled??Ce)(e),a.pressed&&o.setAttribute(`aria-pressed`,String(a.pressed(e))),o.disabled&&s.close()}}),s}let De=(e,t)=>`<${t} class="mde-glyph">${e}</${t}>`,Oe=(e,t,n,r,i,a)=>O(e,t,n,()=>T.chain().focus().toggleMark(r).run(),{pressed:i,enabled:Te,shortcut:a}),ke=[[`paragraph`,`paragraph`],[`sectionHead`,`sectionHead`],[`blockTitle`,`blockTitle`],[`list`,`list`],[`mdNote`,`note`],[`codeBlock`,`codeBlock`],[`docTitle`,`docTitle`]],Ae=null;function je(){Ae&&!Ae.button.disabled&&Ae.open()}let Me=()=>{let{state:e}=T,{from:t,to:n,empty:r}=e.selection,i=e.tr;for(let a of Object.values(e.schema.marks))a.name!==`link`&&(r||i.removeMark(t,n,a));i.setStoredMarks([]),T.view.dispatch(i),T.view.focus()},Ne={undo:()=>O(`undo`,t.undo,$(`undo`),()=>T.chain().focus().undo().run(),{enabled:e=>Ce(e)&&e.canUndo,shortcut:`Z`}),redo:()=>O(`redo`,t.redo,$(`redo`),()=>T.chain().focus().redo().run(),{enabled:e=>Ce(e)&&e.canRedo,shortcut:`Shift+Z`}),blockKind:()=>{let e=Q(`select`,{className:`mde-select`,attrs:{"aria-label":t.blockKind,"data-name":`blockKind`}}),n=Q(`option`,{text:t.tableOrImage,attrs:{value:``}});return e.append(n,...ke.map(([e,n])=>Q(`option`,{text:t[n],attrs:{value:e}}))),e.addEventListener(`change`,()=>{let t=e.value;t&&ev(T.state)!==t&&tv(t)(T.state,T.view.dispatch),T.view.focus()}),Se.push({update:t=>{n.hidden=!!t.kind,e.value=t.kind??``,e.disabled=!Ce(t)||!t.kind}}),e},bold:()=>Oe(`bold`,t.bold,De(`B`,`b`),`bold`,e=>e.bold,`B`),italic:()=>Oe(`italic`,t.italic,De(`I`,`i`),`italic`,e=>e.italic,`I`),underline:()=>Oe(`underline`,t.underline,De(`U`,`u`),`underline`,e=>e.underline,`U`),strike:()=>Oe(`strike`,t.strike,De(`S`,`s`),`strike`,e=>e.strike,`Shift+S`),code:()=>Oe(`code`,t.code,$(`code`),`code`,e=>e.code,`E`),superscript:()=>Oe(`superscript`,t.superscript,`<span class="mde-glyph">x<sup>2</sup></span>`,`superscript`,e=>e.sup,`.`),subscript:()=>Oe(`subscript`,t.subscript,`<span class="mde-glyph">x<sub>2</sub></span>`,`subscript`,e=>e.sub,`,`),highlight:()=>Oe(`highlight`,t.highlight,$(`highlight`),`mdHighlight`,e=>e.highlight,`Shift+H`),removeFormat:()=>O(`removeFormat`,t.removeFormat,$(`removeFormat`),Me,{enabled:Te}),color:()=>Ee(`color`,t.textColor,e=>jw(r===`en`?`A`:`가`,e.color,e.shade),e=>{let n=xe();return Mw(t,n.color,n.shade,!0,t=>(e(),t?T.chain().focus().setMark(`mdColor`,{name:t}).run():T.chain().focus().unsetMark(`mdColor`).run()),()=>(e(),T.chain().focus().toggleMark(`mdShade`).run()))},{enabled:Te}).wrap,link:()=>(Ae=Ee(`link`,t.link,()=>$(`link`),e=>{let n=xe(),r=T.state.selection.empty&&n.link===null;return Nw(t,n.link,r,(t,n)=>{if(e(),r){let e=n||t;T.chain().focus().insertContent({type:`text`,text:e,marks:[{type:`link`,attrs:{href:t}}]}).run()}else T.chain().focus().extendMarkRange(`link`).setLink({href:t}).run()},n.link===null?null:()=>(e(),T.chain().focus().extendMarkRange(`link`).unsetLink().run()))},{enabled:Te,pressed:e=>e.link!==null,shortcut:`K`}),Ae.wrap),bulletList:()=>O(`bulletList`,t.bulletList,$(`bulletList`),()=>E(sv(`bullet`)),{pressed:e=>e.list===`bullet`,shortcut:`Shift+8`}),orderedList:()=>O(`orderedList`,t.orderedList,$(`orderedList`),()=>E(sv(`ordered`)),{pressed:e=>e.list===`ordered`,shortcut:`Shift+7`}),taskList:()=>O(`taskList`,t.taskList,$(`taskList`),()=>E(sv(`task`)),{pressed:e=>e.list===`task`,shortcut:`Shift+9`}),outdent:()=>O(`outdent`,t.outdent,$(`outdent`),()=>E(Z_(-1)),{enabled:e=>Ce(e)&&e.list!==null}),indent:()=>O(`indent`,t.indent,$(`indent`),()=>E(Z_(1)),{enabled:e=>Ce(e)&&e.list!==null}),align:()=>Ee(`align`,t.align,e=>$(Rw.find(([t])=>t===(e.align??`left`))?.[1]??`alignLeft`)+`<span class="mde-caret" aria-hidden="true">▾</span>`,e=>zw(t,lv(T.state),t=>(e(),E(uv(t)))),{enabled:e=>Ce(e)&&e.align!==null}).wrap,table:()=>Ee(`table`,t.insertTable,()=>$(`table`),e=>Pw(t,(t,n)=>(e(),T.chain().focus().insertTable({rows:t,cols:n,withHeaderRow:!0}).run())),{enabled:e=>Ce(e)&&!e.inTable&&!e.inCode}).wrap,image:()=>i.pick?O(`image`,t.insertImage,$(`image`),()=>i.pick(),{enabled:e=>Ce(e)&&!e.inTable}):Ee(`image`,t.insertImage,()=>$(`image`),e=>Lw(t,(t,n)=>(e(),rt.insertImage(t,n)),()=>(e(),w.click())),{enabled:e=>Ce(e)&&!e.inTable}).wrap,codeBlock:()=>O(`codeBlock`,t.codeBlock,$(`codeBlock`),()=>E(tv(`codeBlock`)),{pressed:e=>e.kind===`codeBlock`,enabled:e=>Ce(e)&&!!e.kind,shortcut:`Alt+C`}),horizontalRule:()=>O(`horizontalRule`,t.horizontalRule,$(`horizontalRule`),()=>T.chain().focus().setHorizontalRule().run(),{enabled:e=>Ce(e)&&!e.inTable}),pageBreak:()=>O(`pageBreak`,t.pageBreak,$(`pageBreak`),()=>E(dv),{enabled:e=>Ce(e)&&!e.inTable,shortcut:`Enter`}),specialChars:()=>Ee(`specialChars`,t.specialChars,()=>`<span class="mde-glyph">Ω</span>`,e=>Iw(t,t=>(e(),T.chain().focus().insertContent(t).run())),{enabled:e=>Ce(e)}).wrap,find:()=>O(`find`,t.findReplace,$(`find`),()=>v.hidden?He():Ue(),{pressed:()=>!v.hidden,shortcut:`F`}),source:()=>O(`source`,t.source,`<span class="mde-glyph mde-md">MD</span>`,()=>rt.setMode(s===`source`?`wysiwyg`:`source`),{pressed:e=>e.source,enabled:()=>!0}),preview:()=>O(`preview`,t.preview,$(`preview`),()=>rt.setPreview(!c),{pressed:()=>c,enabled:()=>!0}),pageMarks:()=>O(`pageMarks`,t.pageMarks,$(`pages`),()=>rt.setPageMarksVisible(!u),{pressed:()=>u,enabled:e=>!e.source}),fullscreen:()=>{let e=O(`fullscreen`,t.fullscreen,$(`fullscreen`),()=>rt.setFullscreen(!l),{pressed:()=>l,enabled:()=>!0});return Se.push({update:()=>{let n=l?t.fullscreenExit:t.fullscreen;e.getAttribute(`aria-label`)!==n&&(e.innerHTML=$(l?`fullscreenExit`:`fullscreen`),e.title=n,e.setAttribute(`aria-label`,n))}}),e}},Pe=Q(`input`,{className:`mde-input`,attrs:{type:`search`,placeholder:t.findPlaceholder,"aria-label":t.find,spellcheck:`false`}}),Fe=Q(`input`,{className:`mde-input`,attrs:{type:`text`,placeholder:t.replacePlaceholder,"aria-label":t.replacePlaceholder,spellcheck:`false`}}),Ie=Q(`span`,{className:`mde-find-count`}),Re=Q(`input`,{attrs:{type:`checkbox`}}),ze=(e,t,n,r=!1)=>Q(`button`,{className:`mde-btn${r?` word`:``}`,html:t,title:e,attrs:{type:`button`,"aria-label":e},on:{click:n}}),Be=e=>{let t=Pv(T.state,e);t&&T.view.dispatch(t)};v.append(Pe,Ie,ze(t.findPrev,$(`chevronUp`),()=>Be(-1)),ze(t.findNext,$(`chevronDown`),()=>Be(1)),Q(`label`,{className:`mde-check-label`},Re,t.matchCase),Q(`span`,{className:`mde-sep`}),Fe,ze(t.replace,t.replace,()=>{let e=Fv(T.state,Fe.value);e&&T.view.dispatch(e)},!0),ze(t.replaceAll,t.replaceAll,()=>{let e=Iv(T.state,Fe.value);e&&T.view.dispatch(e)},!0),Q(`span`,{className:`mde-spacer`}),ze(t.close,$(`close`),()=>Ue()));let Ve=()=>T.view.dispatch(Nv(T.state,{query:Pe.value,caseSensitive:Re.checked}));Pe.addEventListener(`input`,Ve),Re.addEventListener(`change`,Ve),Pe.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),Be(e.shiftKey?-1:1)):e.key===`Escape`&&Ue()}),Fe.addEventListener(`keydown`,e=>e.key===`Escape`&&Ue());function He(){if(s===`source`)return;v.hidden=!1;let{from:e,to:t,empty:n}=T.state.selection;!n&&t-e<200&&(Pe.value=T.state.doc.textBetween(e,t,` `),Ve()),Pe.focus(),Pe.select(),tt()}function Ue(){v.hidden=!0,T.view.dispatch(Nv(T.state,{query:``})),T.view.focus()}let We=()=>{let e=kv.getState(T.state);e?.query?Ie.textContent=e.matches.length?ZC(t.findCount,{i:e.index+1,n:e.matches.length}):t.findNone:Ie.textContent=``},Ge=(e,t,n)=>Q(`button`,{className:`mde-btn word`,text:e,title:n??e,attrs:{type:`button`},on:{click:t}}),Ke=Q(`div`,{className:`mde-bar mde-table-bar`,attrs:{role:`toolbar`,"aria-label":t.tableToolbar}},Q(`span`,{className:`mde-bar-label`,text:t.table}),Ge(t.rowAbove,()=>E(K_)),Ge(t.rowBelow,()=>E(G_)),Ge(t.colLeft,()=>T.chain().focus().addColumnBefore().run()),Ge(t.colRight,()=>T.chain().focus().addColumnAfter().run()),Ge(t.deleteRow,()=>T.chain().focus().deleteRow().run()),Ge(t.deleteCol,()=>T.chain().focus().deleteColumn().run()),Q(`span`,{className:`mde-sep`}),Ge(t.mergeCells,()=>E(B_),t.mergeHint),Ge(t.splitCell,()=>T.chain().focus().splitCell().run()),Ge(t.cellShade,()=>E(U_)),Q(`span`,{className:`mde-sep`}),Ge(t.colLeftAlign,()=>E(H_(`left`)),ZC(t.colAlignTitle,{side:t.colLeftAlign})),Ge(t.colCenterAlign,()=>E(H_(`center`)),ZC(t.colAlignTitle,{side:t.colCenterAlign})),Ge(t.colRightAlign,()=>E(H_(`right`)),ZC(t.colAlignTitle,{side:t.colRightAlign})),Q(`span`,{className:`mde-sep`}),Ge(t.deleteTable,()=>T.chain().focus().deleteTable().run())),qe=Q(`input`,{className:`mde-input mde-lang`,attrs:{type:`text`,list:`mde-langs`,placeholder:t.codeLanguageNone,"aria-label":t.codeLanguage,spellcheck:`false`}}),Je=Q(`datalist`,{attrs:{id:`mde-langs`}},...`js.ts.jsx.tsx.json.html.css.py.java.kotlin.swift.go.rust.c.cpp.cs.php.ruby.sql.bash.sh.yaml.toml.xml.md.diff.text`.split(`.`).map(e=>Q(`option`,{attrs:{value:e}})));qe.addEventListener(`change`,()=>{let e=qe.value.trim().split(/\s+/)[0]?.replace(/`/g,``)||null;T.chain().updateAttributes(`codeBlock`,{language:e}).run()}),qe.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),qe.dispatchEvent(new Event(`change`)),T.view.focus())});let Ye=Q(`div`,{className:`mde-bar mde-code-bar`,attrs:{role:`toolbar`,"aria-label":t.codeBlock}},Q(`span`,{className:`mde-bar-label`,text:t.codeBlock}),Q(`label`,{className:`mde-check-label`},t.codeLanguage,qe,Je)),Xe=e=>{let t=e.target;t.closest(`button`)&&!t.closest(`.mde-pop`)&&e.preventDefault()};g.addEventListener(`mousedown`,Xe),y.addEventListener(`mousedown`,Xe);let Ze=0,Qe=null,$e=0;function et(){$e||=requestAnimationFrame(()=>{$e=0,tt()})}function tt(){if($e&&=(cancelAnimationFrame($e),0),!T||T.isDestroyed)return;let e=xe();for(let t of Se)t.update(e);let t=e.source?null:e.inTable?Ke:e.inCode?Ye:null;if(t!==Qe){y.replaceChildren(...t?[t]:[]),Qe=t;let e=y.offsetHeight,n=e-Ze;Ze=e,n&&(ee.scrollTop+=n)}e.inCode&&document.activeElement!==qe&&(qe.value=String(T.state.selection.$from.parent.attrs.language??``)),We()}S.addEventListener(`input`,()=>{D=S.value,m(`change`,D),e.onChange?.(D,rt),_e(),ve()}),S.addEventListener(`paste`,t=>{if(!e.maxLength&&!e.maxPaste)return;let n=le(t.clipboardData).length,r=S.value.length-(S.selectionEnd-S.selectionStart)+n;n&&ce(n,r,S.value.length)&&t.preventDefault()}),S.addEventListener(`keydown`,e=>{e.key===`Tab`&&!e.shiftKey&&(e.preventDefault(),document.execCommand(`insertText`,!1,` `))});let nt=e=>{s=e,h.dataset.mode=e,ee.hidden=e===`source`,S.hidden=e!==`source`,e===`source`&&(v.hidden=!0),tt(),ve(),ge(),m(`mode`,e)},rt={get tiptap(){return T},element:h,messages:t,getMarkdown:()=>D,setMarkdown(e){o||(a=we(e)??a);let t=ct(e,a);be(null),T.commands.setContent(_v(t),{emitUpdate:!1}),D=Tv(T.getJSON(),a),s===`source`&&(S.value=e),_e(),ve()},getDoc:()=>s===`source`?ct(D,a):wv(T.getJSON(),a),setDoc(e){!o&&e.dialect&&(a=e.dialect),T.commands.setContent(_v(e),{emitUpdate:!1}),D=Tv(T.getJSON(),a),s===`source`&&(S.value=D),_e(),ve()},getHTML:()=>wt(rt.getDoc(),{resolveImage:ae}),insertImage(e,t=``){if(s===`source`){let n=S.selectionEnd,r=``;S.setRangeText(`\n\n${r}\n`,n,n,`end`),S.dispatchEvent(new Event(`input`))}else T.chain().focus().insertContent({type:`mdImage`,attrs:{src:e,caption:t}}).run()},replaceImage(e,t){if(s===`source`){let n=t?S.value.split(e).join(t):S.value.split(`
|
|
176
176
|
`).filter(t=>!t.includes(`](${e})`)).join(`
|
|
177
|
-
`);n!==S.value&&(S.value=n,S.dispatchEvent(new Event(`input`)));return}let n=[];if(T.state.doc.descendants((t,r)=>{t.type.name===`mdImage`&&t.attrs.src===e&&n.push({pos:r,size:t.nodeSize,attrs:t.attrs})}),!n.length)return;let r=T.state.tr;for(let e of n.reverse())t?r.setNodeMarkup(e.pos,void 0,{...e.attrs,src:t}):r.delete(e.pos,e.pos+e.size);T.view.dispatch(r.setMeta(`addToHistory`,!1))},refreshImages(){let e=T.state.tr;T.state.doc.descendants((t,n)=>{t.type.name===`mdImage`&&e.setNodeMarkup(n,void 0,{...t.attrs})}),e.steps.length&&T.view.dispatch(e.setMeta(`addToHistory`,!1).setMeta(`preventUpdate`,!0)),_e()},getMode:()=>s,setMode(t){if(t===s)return!0;if(f.current?.close(),t===`source`)return S.value=D,nt(`source`),S.focus(),!0;try{o||(a=we(S.value)??a);let e=ct(S.value,a);T.commands.setContent(_v(e),{emitUpdate:!1})}catch(e){if(e instanceof Le)return be(e),!1;throw e}be(null);let n=D;return D=Tv(T.getJSON(),a),nt(`wysiwyg`),D!==n&&(m(`change`,D),e.onChange?.(D,rt)),T.commands.focus(),!0},isPreview:()=>c,setPreview(e){c=e,h.dataset.preview=e?`on`:`off`,e&&ge(),tt(),m(`preview`,e)},setPageMarks(e){d=e,T.view.dispatch(Vv(T.state,{marks:e})),ve()},isPageMarksVisible:()=>u,setPageMarksVisible(e){e!==u&&(u=e,h.dataset.pagemarks=e?`on`:`off`,T.view.dispatch(Vv(T.state,{visible:e})),tt(),ve(),m(`pagemarks`,e))},isFullscreen:()=>l,setFullscreen(e){l=e,h.classList.toggle(`mde-fullscreen`,e),document.documentElement.classList.toggle(`mde-noscroll`,e),tt(),m(`fullscreen`,e)},setEditable(e){T.setEditable(e),S.readOnly=!e,tt()},setDialect(e){e!==a&&(a=e,s===`wysiwyg`&&(D=Tv(T.getJSON(),a)))},slot:e=>_[e],focus:()=>s===`source`?S.focus():T.commands.focus(),on(e,t){return p[e].add(t),()=>p[e].delete(t)},destroy(){window.clearTimeout(me),window.clearTimeout(C),$e&&cancelAnimationFrame($e),f.current?.close(),document.removeEventListener(`keydown`,st),document.documentElement.classList.remove(`mde-noscroll`),T.destroy(),h.remove()}};g.append(_.start);let it=e.toolbar===!1?[]:e.toolbar??Bw,at=Q(`span`,{className:`mde-group`}),ot=()=>{at.childNodes.length&&g.append(at),at=Q(`span`,{className:`mde-group`})};for(let e of it){if(e===`|`){ot(),g.append(Q(`span`,{className:`mde-sep`,attrs:{role:`separator`}}));continue}let t=typeof e==`string`?Ne[e]?.():e.render(rt);t&&at.append(t)}ot(),g.append(_.end);let st=e=>{e.key===`Escape`&&l&&!f.current&&rt.setFullscreen(!1)};return document.addEventListener(`keydown`,st),h.dataset.preview=c?`on`:`off`,h.dataset.pagemarks=u?`on`:`off`,u&&T.view.dispatch(Vv(T.state,{visible:!0})),oe?(S.value=e.markdown??``,nt(`source`),be(oe)):e.mode===`source`?(S.value=D,nt(`source`)):(tt(),ve(),ge()),rt}e.DEFAULT_TOOLBAR=Bw,e.FindReplace=Mv,e.INLINE_COLORS=r,e.ListNumbers=Ov,e.MARK=a,e.MAX_COLS=ze,e.MAX_LEVEL=Re,e.MdError=Le,e.PageMarksExtension=Bv,e.SHADE=i,e.SPACES=se,e.blockAlign=je,e.blockHtml=Ct,e.blockMd=ht,e.canon=O,e.canonical=Ie,e.cellShade=Ae,e.codeFence=pt,e.colorCss=m,e.colorName=vw,Object.defineProperty(e,"commands",{enumerable:!0,get:function(){return I_}}),e.
|
|
177
|
+
`);n!==S.value&&(S.value=n,S.dispatchEvent(new Event(`input`)));return}let n=[];if(T.state.doc.descendants((t,r)=>{t.type.name===`mdImage`&&t.attrs.src===e&&n.push({pos:r,size:t.nodeSize,attrs:t.attrs})}),!n.length)return;let r=T.state.tr;for(let e of n.reverse())t?r.setNodeMarkup(e.pos,void 0,{...e.attrs,src:t}):r.delete(e.pos,e.pos+e.size);T.view.dispatch(r.setMeta(`addToHistory`,!1))},refreshImages(){let e=T.state.tr;T.state.doc.descendants((t,n)=>{t.type.name===`mdImage`&&e.setNodeMarkup(n,void 0,{...t.attrs})}),e.steps.length&&T.view.dispatch(e.setMeta(`addToHistory`,!1).setMeta(`preventUpdate`,!0)),_e()},getMode:()=>s,setMode(t){if(t===s)return!0;if(f.current?.close(),t===`source`)return S.value=D,nt(`source`),S.focus(),!0;try{o||(a=we(S.value)??a);let e=ct(S.value,a);T.commands.setContent(_v(e),{emitUpdate:!1})}catch(e){if(e instanceof Le)return be(e),!1;throw e}be(null);let n=D;return D=Tv(T.getJSON(),a),nt(`wysiwyg`),D!==n&&(m(`change`,D),e.onChange?.(D,rt)),T.commands.focus(),!0},isPreview:()=>c,setPreview(e){c=e,h.dataset.preview=e?`on`:`off`,e&&ge(),tt(),m(`preview`,e)},setPageMarks(e){d=e,T.view.dispatch(Vv(T.state,{marks:e})),ve()},isPageMarksVisible:()=>u,setPageMarksVisible(e){e!==u&&(u=e,h.dataset.pagemarks=e?`on`:`off`,T.view.dispatch(Vv(T.state,{visible:e})),tt(),ve(),m(`pagemarks`,e))},isFullscreen:()=>l,setFullscreen(e){l=e,h.classList.toggle(`mde-fullscreen`,e),document.documentElement.classList.toggle(`mde-noscroll`,e),tt(),m(`fullscreen`,e)},setEditable(e){T.setEditable(e),S.readOnly=!e,tt()},setDialect(e){e!==a&&(a=e,s===`wysiwyg`&&(D=Tv(T.getJSON(),a)))},slot:e=>_[e],focus:()=>s===`source`?S.focus():T.commands.focus(),on(e,t){return p[e].add(t),()=>p[e].delete(t)},destroy(){window.clearTimeout(me),window.clearTimeout(C),$e&&cancelAnimationFrame($e),f.current?.close(),document.removeEventListener(`keydown`,st),document.documentElement.classList.remove(`mde-noscroll`),T.destroy(),h.remove()}};g.append(_.start);let it=e.toolbar===!1?[]:e.toolbar??Bw,at=Q(`span`,{className:`mde-group`}),ot=()=>{at.childNodes.length&&g.append(at),at=Q(`span`,{className:`mde-group`})};for(let e of it){if(e===`|`){ot(),g.append(Q(`span`,{className:`mde-sep`,attrs:{role:`separator`}}));continue}let t=typeof e==`string`?Ne[e]?.():e.render(rt);t&&at.append(t)}ot(),g.append(_.end);let st=e=>{e.key===`Escape`&&l&&!f.current&&rt.setFullscreen(!1)};return document.addEventListener(`keydown`,st),h.dataset.preview=c?`on`:`off`,h.dataset.pagemarks=u?`on`:`off`,u&&T.view.dispatch(Vv(T.state,{visible:!0})),oe?(S.value=e.markdown??``,nt(`source`),be(oe)):e.mode===`source`?(S.value=D,nt(`source`)):(tt(),ve(),ge()),rt}e.DEFAULT_TOOLBAR=Bw,e.FindReplace=Mv,e.INLINE_COLORS=r,e.ListNumbers=Ov,e.MARK=a,e.MAX_COLS=ze,e.MAX_LEVEL=Re,e.MdError=Le,e.PageMarksExtension=Bv,e.SHADE=i,e.SPACES=se,e.blockAlign=je,e.blockHtml=Ct,e.blockMd=ht,e.canon=O,e.canonical=Ie,e.cellShade=Ae,e.codeFence=pt,e.colorCss=m,e.colorName=vw,Object.defineProperty(e,"commands",{enumerable:!0,get:function(){return I_}}),e.createMDitor=Kw,e.dialectOf=we,e.docToMarkdown=_t,e.escapeHtml=yt,e.findKey=kv,e.fromPM=Tv,e.inlineHtml=bt,e.inlineToMd=yv,e.inlineToPM=pv,e.isColor=p,e.itemLines=ft,e.itemNumbers=xt,e.linkHref=Se,e.listNumbers=Ev,e.marker=Ne,e.messagesEn=YC,e.messagesFor=QC,e.messagesKo=JC,e.normalize=_e,e.oneSpace=Ee,e.pageMarkPlaces=Lv,e.pageMarksKey=Rv,e.parseBlocks=st,e.parseMarkdown=ct,e.plainInline=Oe,e.pmToDoc=wv,e.pyStrip=C,e.renderHtml=wt,e.richExtensions=ww,e.safeHref=Me,e.sectionMd=gt,e.segments=pe,e.spans=Fe,e.splitCells=tt,e.tableData=xv,e.tableMd=Sv,e.tag=ve,e.title=De,e.titleToMd=bv,e.toPM=_v,e.write=Te});
|
|
@@ -2130,7 +2130,7 @@ function Qt(e, t, n) {
|
|
|
2130
2130
|
on: { click: () => n(r) }
|
|
2131
2131
|
})));
|
|
2132
2132
|
}
|
|
2133
|
-
// src/ui/
|
|
2133
|
+
// src/ui/mditor.ts
|
|
2134
2134
|
var $t = /* @__PURE__ */ "undo.redo.|.blockKind.|.bold.italic.underline.strike.color.highlight.|.link.code.superscript.subscript.removeFormat.|.bulletList.orderedList.taskList.outdent.indent.align.|.table.image.codeBlock.horizontalRule.pageBreak.specialChars.|.find.source.preview.fullscreen".split("."), en = typeof navigator < "u" && /Mac|iP(hone|ad|od)/.test(navigator.platform || navigator.userAgent), tn = (e) => en ? `⌘${e.replace("Shift+", "⇧").replace("Alt+", "⌥")}` : `Ctrl+${e}`, nn = /\n|^#{1,6}\s|^[-*+]\s|^\d{1,9}[.)]\s|^>|\*\*|~~|==|`|\[[^\]]*\]\([^)]*\)|\{\/?[^}\s]+\}|^\|/;
|
|
2135
2135
|
function rn(e) {
|
|
2136
2136
|
return e ? [...e.files].filter((e) => e.type.startsWith("image/")) : [];
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as e } from "./
|
|
1
|
+
import { n as e } from "./mditor-rUMGNL2Q.js";
|
|
2
2
|
import { forwardRef as t, useEffect as n, useImperativeHandle as r, useRef as i, useState as a } from "react";
|
|
3
3
|
import { createPortal as o } from "react-dom";
|
|
4
4
|
import { jsxs as s } from "react/jsx-runtime";
|
|
@@ -34,4 +34,4 @@ var c = t(function(t, c) {
|
|
|
34
34
|
children: [u && t.toolbarStart ? o(t.toolbarStart, u.slot("start")) : null, u && t.toolbarEnd ? o(t.toolbarEnd, u.slot("end")) : null]
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
|
-
export { c as
|
|
37
|
+
export { c as MDitorView };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./core";
|
|
2
|
-
export {
|
|
2
|
+
export { createMDitor, DEFAULT_TOOLBAR, type MDitor, type MDitorOptions, type ToolbarItem, type ImageOptions, type MDitorMode } from "./ui/mditor";
|
|
3
3
|
export { messagesFor, ko as messagesKo, en as messagesEn, type Messages, type Locale } from "./ui/messages";
|
|
4
4
|
export { richExtensions, colorName, type RichOptions, type ImageResolver } from "./pm/schema";
|
|
5
5
|
export { toPM, fromPM, pmToDoc, inlineToPM, inlineToMd, titleToMd, tableData, tableMd } from "./pm/convert";
|
package/dist/types/react.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from "react";
|
|
2
|
-
import { type
|
|
3
|
-
export type
|
|
2
|
+
import { type MDitor, type MDitorOptions } from "./ui/mditor";
|
|
3
|
+
export type MDitorViewProps = Omit<MDitorOptions, "element" | "onChange" | "markdown"> & {
|
|
4
4
|
/** 처음 MD(바꿔도 다시 열지 않는다). */
|
|
5
5
|
defaultValue?: string;
|
|
6
6
|
/** 바깥에서 정하는 MD — 편집기의 MD 와 다르면 그것으로 다시 연다. */
|
|
7
7
|
value?: string;
|
|
8
8
|
onChange?: (markdown: string) => void;
|
|
9
9
|
/** 편집기를 만든 뒤 한 번. */
|
|
10
|
-
onReady?: (
|
|
10
|
+
onReady?: (mditor: MDitor) => void;
|
|
11
11
|
className?: string;
|
|
12
12
|
style?: CSSProperties;
|
|
13
13
|
/** 도구 막대 앞 · 뒤에 넣을 쓰는 쪽의 단추. */
|
|
@@ -15,18 +15,18 @@ export type MarkdownEditorViewProps = Omit<MarkdownEditorOptions, "element" | "o
|
|
|
15
15
|
toolbarEnd?: ReactNode;
|
|
16
16
|
};
|
|
17
17
|
/** 편집기는 처음 한 번 만든다. 바뀐 옵션은 value · editable · dialect · preview 만 따라간다(나머지는 key 를 바꿔 다시 만든다). */
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const MDitorView: import("react").ForwardRefExoticComponent<Omit<MDitorOptions, "element" | "onChange" | "markdown"> & {
|
|
19
19
|
/** 처음 MD(바꿔도 다시 열지 않는다). */
|
|
20
20
|
defaultValue?: string;
|
|
21
21
|
/** 바깥에서 정하는 MD — 편집기의 MD 와 다르면 그것으로 다시 연다. */
|
|
22
22
|
value?: string;
|
|
23
23
|
onChange?: (markdown: string) => void;
|
|
24
24
|
/** 편집기를 만든 뒤 한 번. */
|
|
25
|
-
onReady?: (
|
|
25
|
+
onReady?: (mditor: MDitor) => void;
|
|
26
26
|
className?: string;
|
|
27
27
|
style?: CSSProperties;
|
|
28
28
|
/** 도구 막대 앞 · 뒤에 넣을 쓰는 쪽의 단추. */
|
|
29
29
|
toolbarStart?: ReactNode;
|
|
30
30
|
toolbarEnd?: ReactNode;
|
|
31
|
-
} & import("react").RefAttributes<
|
|
32
|
-
export type {
|
|
31
|
+
} & import("react").RefAttributes<MDitor | null>>;
|
|
32
|
+
export type { MDitor, MDitorOptions };
|
|
@@ -3,11 +3,11 @@ import { type Dialect } from "../core/inline";
|
|
|
3
3
|
import { type Doc } from "../core/types";
|
|
4
4
|
import { type PageMarks } from "../pm/plugins";
|
|
5
5
|
import { type Locale, type Messages } from "./messages";
|
|
6
|
-
export type
|
|
6
|
+
export type MDitorMode = "wysiwyg" | "source";
|
|
7
7
|
/** 도구 막대 항목 — 이름(아래 DEFAULT_TOOLBAR 참고), "|"(구분선), 또는 직접 그리는 항목. */
|
|
8
8
|
export type ToolbarItem = string | {
|
|
9
9
|
name: string;
|
|
10
|
-
render: (editor:
|
|
10
|
+
render: (editor: MDitor) => HTMLElement;
|
|
11
11
|
};
|
|
12
12
|
export declare const DEFAULT_TOOLBAR: ToolbarItem[];
|
|
13
13
|
export type ImageOptions = {
|
|
@@ -20,7 +20,7 @@ export type ImageOptions = {
|
|
|
20
20
|
/** 이미지 단추를 누르면 부른다(쓰는 쪽의 파일 고르기). 없으면 주소 · 파일 팝업을 연다. */
|
|
21
21
|
pick?: () => void;
|
|
22
22
|
};
|
|
23
|
-
export type
|
|
23
|
+
export type MDitorOptions = {
|
|
24
24
|
/** 편집기를 넣을 요소. */
|
|
25
25
|
element: HTMLElement;
|
|
26
26
|
/** 처음 열 MD. */
|
|
@@ -43,7 +43,7 @@ export type MarkdownEditorOptions = {
|
|
|
43
43
|
*/
|
|
44
44
|
pageMarks?: boolean;
|
|
45
45
|
/** 처음 모드 — 문서(wysiwyg) 또는 MD 원문(source). */
|
|
46
|
-
mode?:
|
|
46
|
+
mode?: MDitorMode;
|
|
47
47
|
/** 글자 수 줄(기본 true). */
|
|
48
48
|
statusbar?: boolean;
|
|
49
49
|
/** 고칠 수 있는가(기본 true). */
|
|
@@ -54,7 +54,7 @@ export type MarkdownEditorOptions = {
|
|
|
54
54
|
contentClass?: string;
|
|
55
55
|
image?: ImageOptions;
|
|
56
56
|
/** 글이 바뀔 때마다(MD). */
|
|
57
|
-
onChange?: (markdown: string, editor:
|
|
57
|
+
onChange?: (markdown: string, editor: MDitor) => void;
|
|
58
58
|
/**
|
|
59
59
|
* 문서(MD) 길이 한도. 붙이면 이 길이를 넘는 붙여넣기는 받지 않는다(한 번에 큰 글을 붙여 서버 · 브라우저가 무거워지지 않게).
|
|
60
60
|
* 손으로 치는 글은 막지 않는다.
|
|
@@ -73,12 +73,12 @@ export type MarkdownEditorOptions = {
|
|
|
73
73
|
};
|
|
74
74
|
type Events = {
|
|
75
75
|
change: (md: string) => void;
|
|
76
|
-
mode: (mode:
|
|
76
|
+
mode: (mode: MDitorMode) => void;
|
|
77
77
|
preview: (on: boolean) => void;
|
|
78
78
|
fullscreen: (on: boolean) => void;
|
|
79
79
|
pagemarks: (on: boolean) => void;
|
|
80
80
|
};
|
|
81
|
-
export interface
|
|
81
|
+
export interface MDitor {
|
|
82
82
|
/** 속의 TipTap 편집기. */
|
|
83
83
|
readonly tiptap: Editor;
|
|
84
84
|
readonly element: HTMLElement;
|
|
@@ -95,9 +95,9 @@ export interface MarkdownEditor {
|
|
|
95
95
|
replaceImage(from: string, to: string | null): void;
|
|
96
96
|
/** 그림 주소 풀이(resolve)가 바뀌었을 때 그림을 다시 그린다. */
|
|
97
97
|
refreshImages(): void;
|
|
98
|
-
getMode():
|
|
98
|
+
getMode(): MDitorMode;
|
|
99
99
|
/** 모드를 바꾼다. MD 원문 → 문서가 실패하면(읽을 수 없는 MD) false. */
|
|
100
|
-
setMode(mode:
|
|
100
|
+
setMode(mode: MDitorMode): boolean;
|
|
101
101
|
isPreview(): boolean;
|
|
102
102
|
setPreview(on: boolean): void;
|
|
103
103
|
/** 쪽 경계 자리를 넘긴다(null 이면 지운다). 새 경계가 오기 전까지는 글을 고쳐도 경계가 글을 따라 움직인다. */
|
|
@@ -114,5 +114,5 @@ export interface MarkdownEditor {
|
|
|
114
114
|
on<K extends keyof Events>(event: K, fn: Events[K]): () => void;
|
|
115
115
|
destroy(): void;
|
|
116
116
|
}
|
|
117
|
-
export declare function
|
|
117
|
+
export declare function createMDitor(options: MDitorOptions): MDitor;
|
|
118
118
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@watalabs/lasee-mditor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Markdown document editor — edit what you see, keep Markdown as the source. Toolbar, tables with merged cells, lists, code blocks, find & replace, source mode, preview.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "WataLabs (https://watalabs.com)",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/madorik/mditor-lasee.git",
|
|
11
|
-
"directory": "web/packages/
|
|
11
|
+
"directory": "web/packages/lasee-mditor"
|
|
12
12
|
},
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/madorik/mditor-lasee/issues"
|